/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.braincasedesigns.roller.model;

import com.braincasedesigns.roller.model.Die;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 *
 * @author jcampbel
 */
public class PolyhedralDie implements Die<PolyhedralFace>{
    
    private Random random = new Random();
    
    private final int sides;
    
    private final String notation;

    public PolyhedralDie(int sides){
        this.sides = sides;
        StringBuilder buf = new StringBuilder("d");
        buf.append(sides);
        notation = buf.toString();
    }
    
    
    public int getFaces() {
        return sides;
    }

    public int getIndex(PolyhedralFace f) throws IllegalArgumentException {
        if (f.getNumericRepresentation() > sides){
            throw new IllegalArgumentException("Invalid Face:"+f);
        }
        else {
            //Since this is a simple case we just use the face value -1 as the index 
            return f.getNumericRepresentation()-1;
        }
    }

    public PolyhedralFace getFace(int idx) throws IllegalArgumentException {
        if (idx >= sides){
            throw new IllegalArgumentException("Invalid index.");
        }
        return new PolyhedralFace(idx+1);
        
    }

    public int add(int idx, int val) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public PolyhedralFace add(PolyhedralFace f, int val) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public PolyhedralFace roll() {
        return getFace(random.nextInt(sides));
    }
    
    public String getNotation(){
        return notation;
    }
}
